package com.ln;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

@SpringBootTest
class Redis2ApplicationTests02 {
    //该类中封装了很多api方法  redis服务
    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    public void test01(){
    //默认RedisTemplate它的key和value的序列化都是使用的JdkSerializationRedisSerializer方式，该序列化要求类必须实现Serializable接口。
    //我们在实际开发中，我们的key都是String类型，我们应该指定String序列化方式
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
    ValueOperations valueOperations = redisTemplate.opsForValue();
    valueOperations.set("k4",new Student("王德法","18","男"));
    System.out.println(valueOperations.get("k4"));

    }

}
